<!--
 * @Description: 
 * @Author: ZachGmy
 * @Date: 2022-08-25 16:06:58
 * @LastEditors: HeAo
 * @LastEditTime: 2022-08-27 09:21:38
-->
<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>

<body>
  <button onclick="getData()">获取数据</button>
  <script>
    function getData() {
      // 1.创建XMLHttpRequest实例对象
      var request = new XMLHttpRequest()
      // 2.配置请求方式，设置请求接口地址
      // 使用open方法设置和服务器的交互信息
      request.open('get', 'http://121.4.83.32:7004/carousel/findAll')
      // 3.设置请求头的格式
      // 设置requestHeader()
      // 4.发送请求
      request.send()
      // 5.获取网络请求返回的数据
      request.onreadystatechange = function () {
        if (request.readyState === 4 && request.status === 200) {
          console.log(JSON.parse(request.responseText));
          var res = JSON.parse(request.responseText)
          // DOM
          // 创建节点
          for (var index in res.data) {
            var div = document.createElement('div')
            // 数据赋值
            // 将节点添加到DOM结构中
            div.innerHTML = res.data[index].introduce
            document.body.appendChild(div)
          }
        }
      }
    }
  </script>
</body>

</html>